﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="tablecloth/tablecloth.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="tablecloth/tablecloth.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>


<?php

	include("inc/joomlaInt.php");
	include("inc/inc_configuration.php");

if ($jUser==0)
{
	echo "Bitte zuerst einloggen!";
}
else
{
	
	$matchId=$_GET["matchId"];

	
	$hG=0;
	$hY=0;
	$hYR=0;
	$hR=0;
	$hOG=0;
	
	$gG=0;
	$gY=0;
	$gYR=0;
	$gR=0;
	$gOG=0;
	
	
	$query = "	SELECT e.type, p.teamId, COUNT(*) AS anz 
				FROM	$tbl_events e, $tbl_matches m, $tbl_players p
				WHERE
					m.id=$matchId AND
					m.id=e.matchId AND
					e.playerId=p.id
				GROUP BY p.teamId,e.type";
	$q = mysql_query($query);
	
	$tquery = "	SELECT homeT,guestT,t1.name AS homeN, t2.name AS guestN 
				FROM $tbl_matches m, $tbl_teams t1, $tbl_teams t2 WHERE m.id=$matchId AND m.homeT=t1.id AND m.guestT=t2.id";
	$tq = mysql_query($tquery);
	$tqe = mysql_fetch_object($tq);
	
	$tHi=$tqe->homeT;
	$tGi=$tqe->guestT;
	$tHn=$tqe->homeN;
	$tGn=$tqe->guestN;
	
	while($i = mysql_fetch_object($q))
	{
		$type=$i->type;
		$team=$i->teamId;
		$anz=$i->anz;
		
		if ($team==$tHi)
		{
			if (($type==1) OR ($type==5) OR ($type==6))
			{
				if ($type==6) {$gG=$gG+$anz; $hOG++;} else
				{
					$hG=$hG+$anz;
				}
			}
			else
				{
					if ($type==2)
					{
						$hY=$anz;
					}
					else
						{
							if ($type==3)
							{
								$hYR=$anz;
							}
						
							else
								{
									if ($type==4)
									{
										$hR=$anz;
									}
								}
						}
				}
		}
		else
			{
				if ($team==$tGi)
				{
					if (($type==1) OR ($type==5) OR ($type==6))
					{
						if ($type==6) { $hG=$hG+$anz; $gOG++; } else
						{
							$gG=$gG+$anz;
						}
					}
					else
						{
							if ($type==2)
							{
								$gY=$anz;
							}
							else
								{
									if ($type==3)
									{
										$gYR=$anz;
									}
								
									else
										{
											if ($type==4)
											{
												$gR=$anz;
											}
										}
								}
						}
				}
			
			}
			
		
	}
	
	$hG=$hG-$gOG;
	$gG=$gG-$hOG;
	
	
	echo "	<form action='spiel_bearbeiten_v.php?matchId=$matchId' method='post'>";
	
	echo "<input type='hidden' name='tHi' value='$tHi'>";
	echo "<input type='hidden' name='tGi' value='$tGi'>";
	
	echo "<input type='hidden' name='tHn' value='$tHn'>";
	echo "<input type='hidden' name='tGn' value='$tGn'>";
	echo "<input type='hidden' name='uHn' value='$uHn'>";
	echo "<input type='hidden' name='uGn' value='$uGn'>";
	echo "<input type='hidden' name='matchId' value='$matchId'>";
	
	echo "<table>
			<tr><th colspan='5'></th></tr>
			<tr>
				<td></td>
				<td><center>$tHn<br>$uHn</center></td>
				<td>:</td>
				<td><center>$tGn<br>$uGn</center></td>
				<td></td>
			</tr>
			<tr>
				<td><center>Tore</center></td>
				<td><input type='text' name='hG' value='$hG'></td>
				<td>:</td>
				<td><input type='text' name='gG' value='$gG'></td>
				<td><center>Tore</center></td>
			</tr>
			<tr>
				<td><center>Eigentore</center></td>
				<td><input type='text' name='hOG' value='$hOG'></td>
				<td>:</td>
				<td><input type='text' name='gOG' value='$gOG'></td>
				<td><center>Eigentore</center></td>
			</tr>
			<tr>
				<td><center>Gelbe Karten</center></td>
				<td><input type='text' name='hY' value='$hY'></td>
				<td>:</td>
				<td><input type='text' name='gY' value='$gY'></td>
				<td><center>Gelbe Karten</center></td>
			</tr>
			<tr>
				<td><center>Gelb-Rote Karten</center></td>
				<td><input type='text' name='hYR' value='$hYR'></td>
				<td>:</td>
				<td><input type='text' name='gYR' value='$gYR'></td>
				<td><center>Gelb-Rote Karten</center></td>
			</tr>
			<tr>
				<td><center>Rote Karten</center></td>
				<td><input type='text' name='hR' value='$hR'></td>
				<td>:</td>
				<td><input type='text' name='gR' value='$gR'></td>
				<td><center>Rote Karten</center></td>
			</tr>
			<tr><th colspan='5'></th></tr>
			";
	
	
	
	echo "</table><br><input type='submit' value='Weiter' class='button weiter'></form>";
	
	
	
	
	echo '<center><br><br><a href="lima.php" class="button zurueck">Zurück</a></center>';
}
	
	
	
?>

</body>
</html>